package com.wuye.service.impl;

import com.wuye.model.User;
import com.wuye.repository.UserRepository;
import com.wuye.service.UserService;
import com.wuye.web.ST;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by admin on 2016/6/6.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    private Log log= LogFactory.getLog(this.getClass());

    @Autowired
    private UserRepository userRepository;

    @Override
    public User checkUser(String cellPhone) throws RuntimeException {
        User user = userRepository.findByCellPhone(cellPhone);
        return user;
    }

    @Override
    public void modifyPassword(String newPassword, String cellPhone) throws RuntimeException {
        User user = userRepository.findByCellPhone(cellPhone);
        if(user==null){
            throw new RuntimeException("user not exist");
        }else{
            user.setPassword(newPassword);
            userRepository.save(user);
        }
    }

    @Override
    public void saveUser(User user) throws RuntimeException {
        userRepository.save(user);
    }
	public User findByUserId(String userId){
		return userRepository.findByUserId(userId);
	}
}
